/*
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-10-12 13:00:38
 * @LastEditTime: 2019-11-05 12:32:58
 * @LastEditors: Please set LastEditors
 */
const Koa = require('koa');
const app = new Koa();
const koaStatic = require('koa-static');
const parameter =require('koa-parameter');
const routing =require('./Router/index')
const koaBody = require('koa-body');
const error = require('koa-json-error');
const mongoose =require('mongoose');
const {connectionStr}=require('./config');
const path =require('path')


mongoose.connect(connectionStr,{ useNewUrlParser: true ,useUnifiedTopology: true},()=>console.log('mongoDB连接成功'))
mongoose.connection.on('error',console.error)
mongoose.set('useFindAndModify', false);
app.use(error(
    {postFormat:(error,{stack,...rest})=>process.env.NODE_ENV==='production'?rest:{stack,...rest}}
));
app.use(koaStatic(path.join(__dirname,'publick')));
app.use(koaBody({
    multipart:true,//开启文件上传的功能
    formidable:{//设置文件格式
        uploadDir:path.join(__dirname,'/publick/uploads'),//上传的文件目录
        keepExtensions:true,//文件后著名
    }
}));
app.use(parameter(app));
routing(app)
app.listen(8000, () => {
    console.log("this is a zhhu serve")
})